# The list of individual toadlet base libraries
set (TOADLET_LIBRARY_LIST
	egg
	flick
	hop
	peeper
	ribbit
	tadpole
	pad
)


# Add the individual toadlet base libraries
foreach (TOADLET_LIBRARY ${TOADLET_LIBRARY_LIST})
	add_subdirectory (${TOADLET_LIBRARY})
endforeach (TOADLET_LIBRARY)


# Create the aggregate toadlet include files
# This uses the libraryname_HEADERS variable from each base library 
# As well as the libraryname_NAMESPACES variable for the namespaces
foreach (TOADLET_LIBRARY ${TOADLET_LIBRARY_LIST})
	string (TOUPPER ${TOADLET_LIBRARY} UPPERNAME)
	set (HEADER_FILE "${toadlet_BINARY_DIR}/source/cpp/toadlet/${TOADLET_LIBRARY}.h")

	file (WRITE ${HEADER_FILE} "/* This file is autogenerated */\n")
	file (APPEND ${HEADER_FILE} "#ifndef TOADLET_${UPPERNAME}_H\n")
	file (APPEND ${HEADER_FILE} "#define TOADLET_${UPPERNAME}_H\n")
	file (APPEND ${HEADER_FILE} ""\n)

	foreach (H_FILE ${${UPPERNAME}_HEADERS})
		file (APPEND ${HEADER_FILE} "#include <toadlet/${TOADLET_LIBRARY}/${H_FILE}>\n")
	endforeach (H_FILE)

	file (APPEND ${HEADER_FILE} ""\n)

	file (APPEND ${HEADER_FILE} "using namespace toadlet;\n")
	file (APPEND ${HEADER_FILE} "using namespace toadlet::${TOADLET_LIBRARY};\n")
	foreach (NAMESPACE ${${UPPERNAME}_NAMESPACES})
		file (APPEND ${HEADER_FILE} "using namespace toadlet::${TOADLET_LIBRARY}::${NAMESPACE};\n")
	endforeach (NAMESPACE)

	file (APPEND ${HEADER_FILE} "\n")
	file (APPEND ${HEADER_FILE} "#endif\n")
endforeach (TOADLET_LIBRARY)


# Create the master toadlet include file
set (HEADER_FILE "${toadlet_BINARY_DIR}/source/cpp/toadlet/toadlet.h")

file (WRITE ${HEADER_FILE} "/* This file is autogenerated */\n")
file (APPEND ${HEADER_FILE} "#ifndef TOADLET_H\n")
file (APPEND ${HEADER_FILE} "#define TOADLET_H\n")
file (APPEND ${HEADER_FILE} ""\n)

foreach (TOADLET_LIBRARY ${TOADLET_LIBRARY_LIST})
	file (APPEND ${HEADER_FILE} "#include <toadlet/${TOADLET_LIBRARY}.h>\n")
endforeach (TOADLET_LIBRARY)

file (APPEND ${HEADER_FILE} "\n")
file (APPEND ${HEADER_FILE} "#endif\n")


# Setup toadlet's configure file
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/Config.h)


# Install header files 
if (NOT INSTALL_ANDROID_APP)
	install (FILES ${toadlet_SOURCE_DIR}/source/cpp/toadlet/Types.h DESTINATION include/toadlet)
	install (FILES ${toadlet_BINARY_DIR}/source/cpp/toadlet/Config.h DESTINATION include/toadlet)
	foreach (TOADLET_LIBRARY ${TOADLET_LIBRARY_LIST})
		install (DIRECTORY ${toadlet_SOURCE_DIR}/source/cpp/toadlet/${TOADLET_LIBRARY}  DESTINATION include/toadlet FILES_MATCHING PATTERN "*.h")
		install (FILES ${toadlet_BINARY_DIR}/source/cpp/toadlet/${TOADLET_LIBRARY}.h DESTINATION include/toadlet)

		# Each library's version file is configured by that library and installed here
		install (FILES  ${toadlet_BINARY_DIR}/source/cpp/toadlet/${TOADLET_LIBRARY}/Version.h DESTINATION include/toadlet/${TOADLET_LIBRARY})
	endforeach (TOADLET_LIBRARY)
	install (FILES ${toadlet_BINARY_DIR}/source/cpp/toadlet/toadlet.h DESTINATION include/toadlet)
endif (NOT INSTALL_ANDROID_APP)

